package com.th.supcom.pds.recipefee.client.widget;

import java.util.List;

import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.th.supcom.pds.config.client.model.PhamWindowConfigModel;
import com.th.supcom.pds.config.client.service.PhamWindowConfigRpc;
import com.th.supcom.pds.config.client.service.PhamWindowConfigRpcAsync;

/**
 * 出库窗口
 */
public class OutputWindowCombox extends ComboBox <PhamWindowConfigModel>
{
    /**
     * 公司版权信息.
     */
    public static final String copyright = "Copyright 2014, Carefx Corporation";

    /**
     * 提交路径.
     */
    public static final String SCC_BRANCH = "$URL$";

    /**
     * 提交日期.
     */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /**
     * 最终修改人员.
     */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /**
     * 最终版本号.
     */
    public static final String SCC_REVISION = "$Revision$";

    private final PhamWindowConfigRpcAsync m_phamWindowConfigRpcAsync = GWT.create (PhamWindowConfigRpc.class);

    public OutputWindowCombox (String deptCode)
    {
        store = new ListStore <PhamWindowConfigModel> ();
        super.setDisplayField ("windowName");
        this.setInputStyleAttribute ("font-family", "黑体");
        this.setInputStyleAttribute ("font-size", "30px");
        this.setInputStyleAttribute ("text-align", "center");
        super.setTriggerAction (TriggerAction.ALL);
        super.setWidth (width);
        loadData (deptCode);
    }

    private void loadData (String deptCode)
    {
        PhamWindowConfigModel model=new  PhamWindowConfigModel();
        model.setDeptCode (deptCode);
        model.setOpenFlag (1);
        m_phamWindowConfigRpcAsync.findPhamWindowConfigByExample (model, new AsyncCallback <List <PhamWindowConfigModel>> ()
        {

            @Override
            public void onFailure (final Throwable caught)
            {
                MessageBox.alert ("警告", caught.getMessage (), null);
                return;
            }

            @Override
            public void onSuccess (final List <PhamWindowConfigModel> result)
            {
                store.removeAll ();
                store.add (result);
            }
        });
    }

}
